package com.sl.springboot.service.impl;

import com.sl.springboot.dao.UcardDao;
import com.sl.springboot.model.Ucard;
import com.sl.springboot.model.PageInfo;
import com.sl.springboot.model.UcardVO;
import com.sl.springboot.service.UcardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.sl.springboot.util.RandomIdUtil;

/**
 * 用户Service接口实现类
 * @author: mty
 */
@Service("ucardService")
@Transactional
public class UcardServiceImpl implements UcardService {

    @Autowired
    private UcardDao ucardDao;


    //分页查询
    @Override
    public PageInfo<Ucard> findPageInfo(Integer pageIndex, Integer pageSize,Map mp) {
        PageInfo<Ucard> pi = new PageInfo<Ucard>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        mp.put("currentPage",(pi.getPageIndex()-1)*pi.getPageSize());
        mp.put("pageSize",pi.getPageSize());
        //获取总条数
        Integer totalCount = ucardDao.totalCount(mp);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //按条件查询
            List<Ucard> ucardList =	ucardDao.getUcardList(mp);
            pi.setList(ucardList);
        }
        return pi;
    }


    //添加
    @Override
    public int addUcard(Ucard ucard) {
        ucard.setId(RandomIdUtil.getRandomIdByUUID());
        return ucardDao.addUcard(ucard);
    }


    //根据id删除
    @Override
    public int deleteUcard(String id) {
        return ucardDao.deleteUcard(id);
    }


    //修改宿舍信息
    @Override
    public int updateUcard(Ucard ucard) {
        return ucardDao.updateUcard(ucard);
    }

    //根据ID查询
    @Override
    public Ucard findUcardById (String id){
        Ucard d = ucardDao.findUcardById(id);
        return  d;
    }

    //查询所有
    @Override
    public List<Ucard> getAll(){
        List<Ucard> ucardList = ucardDao.getAll();
        return ucardList;
    }

    //按照条件查询
    @Override
    public List<Ucard> queryFilter(Map mp){
        List<Ucard> ucardList = ucardDao.queryFilter(mp);
        return ucardList;
    }

    @Override
    public List<UcardVO> queryFilter1(Map mp){
        List<UcardVO> ucardList = ucardDao.queryFilter1(mp);
        return ucardList;
    }
}
